<template>
  <!-- 商家信息页 -->
  <div class="wty-shop">
    <div class="wty-shop-header-wrapper">
      <WtyShopHeader></WtyShopHeader>
    </div>
    <div class="wty-shop-content-wrapper">
      <div class="wty-carousel-wrapper">
        <el-carousel :interval="5000" arrow="always">
          <el-carousel-item v-for="(item, index) in imgs" :key="index">
            <div>
              <img :src="item" alt />
            </div>
          </el-carousel-item>
        </el-carousel>
      </div>
      <div class="wty-shop-router-view">
        <div class="wty-shop-content-nav">
          <ul class="wty-shop-nav-links">
            <li
              class="wty-shop-nav-item"
              @click="_navActive(index)"
              v-for="(item, index) in links"
              :key="index"
            >
              <router-link
                :class="{ active: item.isActive }"
                class="wty-shop-nav-item-link"
                :to="item.href"
                >{{ item.text }}</router-link
              >
            </li>
          </ul>
        </div>
      </div>
      <div class="wty-shop-router-wrapper">
        <div class="wty-shop-router-wrapper-inner">
          <router-view
            :goods="goods"
            @addCount="_addCount"
            @minusCount="_minusCount"
          ></router-view>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import WtyShopHeader from "@/components/shop/header/wty-shop-header.vue";
import Axios from "axios";
import Vue from "vue";
export default {
  data() {
    return {
      imgs: [
        "http://p0.meituan.net/codeman/daa73310c9e57454dc97f0146640fd9f69772.jpg",
        "http://p1.meituan.net/codeman/826a5ed09dab49af658c34624d75491861404.jpg",
        "http://p0.meituan.net/codeman/a97baf515235f4c5a2b1323a741e577185048.jpg",
        "http://p0.meituan.net/codeman/33ff80dc00f832d697f3e20fc030799560495.jpg",
        "https://p1.meituan.net/travelcube/01d2ab1efac6e2b7adcfcdf57b8cb5481085686.png"
      ],
      links: [
        {
          text: "菜单",
          href: "/shop/wty-menu",
          isActive: true
        },
        {
          text: "评价",
          href: "/shop/wty-evaluate",
          isActive: false
        },
        {
          text: "食品安全档案",
          href: "/shop/wty-safety",
          isActive: false
        }
      ],
      goods: []
    };
  },
  created() {
    Axios.get("http://192.168.101.74:9000/shop").then(resp => {
      this.goods = resp.data;
      this.goods.forEach(good => {
        good.list.forEach(its => {
          Vue.set(its, "count", 0); // 增加一个属性 count
        });
      });
    });
  },
  methods: {
    _addCount(a, b) {
      this.goods[a].list[b].count++;
    },
    _minusCount(a, b) {
      this.goods[a].list[b].count = Math.max(0, --this.goods[a].list[b].count);
    }
  },
  components: {
    WtyShopHeader
  }
};
</script>

<style lang="scss" scoped>
.wty-shop {
  .wty-shop-header-wrapper {
    width: 100%;
    height: 70px;
  }
  .wty-shop-content-wrapper {
    box-shadow: 0 20px 20px rgba($color: #000000, $alpha: 0.1) inset;
    background-color: #f5f5f5;
    .wty-carousel-wrapper {
      width: 980px;
      margin: 0 auto;
    }
    .wty-shop-router-view {
      width: 980px;
      margin: 20px auto 0 auto;

      .wty-shop-content-nav {
        width: 660px;
        background-color: #fff;
        height: 50px;
        box-sizing: border-box;
        border-bottom: 1px solid rgba(7, 17, 27, 0.1);

        .wty-shop-nav-links {
          height: 50px;
          font-size: 0;

          .wty-shop-nav-item {
            display: inline-block;
            height: 50px;
            line-height: 50px;

            .wty-shop-nav-item-link {
              display: inline-block;
              font-size: 16px;
              font-weight: 400;
              color: #000;
              margin: 0 30px;
              height: 50px;
              line-height: 50px;
              box-sizing: border-box;

              &.active {
                border-bottom: 3px solid #ffa627;
              }
            }
          }
        }
      }
    }
    .wty-shop-router-wrapper {
      width: 980px;
      margin: 20px auto 0 auto;
      .wty-shop-router-wrapper-inner {
        width: 660px;
      }
    }
  }
}
</style>
